package twentytwentyone_3;

import java.util.Arrays;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2021-03-08 8:45
 * @Modified By:
 */
public class NextGreaterElement_496 {

    public static void main(String [] args){
        int[] nums1 = new int[]{1};
        int[] nums2 = new int[]{1,2};
        System.out.println(Arrays.toString(nextGreaterElement(nums1, nums2)));
    }

    public static int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int [] result = new int[nums1.length];
        Arrays.fill(result, -1);
        int index = 0;
        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                if (nums1[i] == nums2[j]){
                    index = j;
                    break;
                }
            }
            for (int j = index; j < nums2.length; j++) {
                if (nums1[i] < nums2[j]){
                    result[i] = nums2[j];
                    break;
                }
            }
        }
        return result;
    }
}
